//
//  TimerControl.m
//  iCodeMac
//
//  Created by Andrew Barry on 3/04/09.
//  Copyright 2009 Barry Computer Services. All rights reserved.
//

#import "TimerControl.h"
#import "ImageView.h"

@implementation TimerControl
-(id) init {
	self = [super init];
	period = 1000;
	return self;
}

-(id) valueForProperty: (NSString *) name {
	if ([name isEqualToString:@"period"]) {
		return [NSNumber numberWithInt:period];
	} else if ([name isEqualToString:@"repeating"]) {
		return [NSNumber numberWithBool:repeating];
	}
	return [super valueForProperty: name];
}

-(void) setValue: (id) val forProperty:(NSString*) name {
	if ([name isEqualToString:@"period"]) {
		period = [val intValue];
	} else if ([name isEqualToString:@"repeating"]) {
		repeating = [val boolValue];
	} else {
		[super setValue: val forProperty: name];
	}
}

-(NSArray *) getEvents {
	return [NSArray arrayWithObjects:@"Action", nil];
}

-(void) saveFields: (NSMutableDictionary *) content {
	[content setObject:[NSNumber numberWithInt:period] forKey:@"period"];
	[content setObject:[NSNumber numberWithBool:repeating] forKey:@"repeating"];
	[super saveFields: content];
}

-(NSView *) load: (NSDictionary *) defn withFrame: (NSRect) frame {
	period = [[defn objectForKey:@"period"] intValue];
	repeating = [[defn objectForKey:@"period"] boolValue];
	
	ImageView *vw = [[ImageView alloc] initWithFrame:frame withImage:@"timer"];
	return vw;
}

-(NSString *) propsNibName {
	return @"TimerProps";
}

-(NSArray *) autocompletes {
	return [NSArray arrayWithObjects: @"period", @"repeating", @"start(", @"stop(", nil];
}
@end
